package com.zzh.tree;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class No144_preorderTraversal {
    public static void main(String[] args) {
        No144Solution solution = new No144Solution();
        List<Integer> list = solution.preorderTraversal(TreeNode.initTree());
        System.out.println(Arrays.toString(list.toArray()));

    }
}
class No144Solution{
    private List<Integer> list;
    public List<Integer> preorderTraversal(TreeNode root) {
        if (root==null){
            return new ArrayList<>();
        }
        list=new ArrayList<>();
        preOrder(root);
        return list;
    }
    public void preOrder(TreeNode root){
        if (root==null){
            return ;
        }
        list.add(root.val);
        preOrder(root.left);
        preOrder(root.right);
    }
}
